;+
; NAME:
;  hod_resultstruct
; PURPOSE:
;  Turns ascii output of HOD code into a structure
; CALLING SEQUENCE:
;  outstruct=hod_resultstruct(result)
; INPUTS:
;  result : array of string output lines of HOD code
; OUTPUT:
;  outstruct : structure with tags:
;    r_p,w_p_1halo,w_p_2halo,w_p_sum,xi_1halo,xi_2halo,xi_sum
; MODIFICATION HISTORY:
;  Created 1st Nov. 2010 - J. Aird
;-
function create_hodmod_struct,nelem
 out=create_struct('r_p',fltarr(nelem),$
                   'w_p_1halo',fltarr(nelem),$
                   'w_p_2halo',fltarr(nelem),$
                   'w_p_sum',fltarr(nelem),$
                   'xi_1halo',fltarr(nelem),$
                   'xi_2halo',fltarr(nelem),$
                   'xi_sum',fltarr(nelem),$
                   'bias',0.0,$ 
                   'b_sat',0.0,$
                   'b_cen',0.0,$
                   'LgMeff',0.0,$
                   'sat1',0.0,$
                   'cen1',0.0,$
                   'Density',0.0,$
                   'sat2',0.0,$
                   'cen2',0.0)

 return,out
end
                             
function hod_resultstruct,result

if n_elements(result) eq 0 then $
  message,"input required"


nlines=n_elements(result)

w=where(stregex(result,'!',/boolean) eq 0,nelem)
res=result[w]

outstruct=create_hodmod_struct(nelem)
out1=fltarr(7,nelem)

reads,res,out1
outstruct.r_p=out1[0,*]
outstruct.w_p_1halo=out1[1,*]
outstruct.w_p_2halo=out1[2,*]
outstruct.w_p_sum=out1[3,*]
outstruct.xi_1halo=out1[4,*]
outstruct.xi_2halo=out1[5,*]
outstruct.xi_sum=out1[6,*]

q=where(strcmp(result,'! Samp1',7) gt 0,n)
t=strsplit(result[q],' ',/extract)
outstruct.bias = t[2]
outstruct.b_sat = t[3]
outstruct.b_cen= t[4]
outstruct.LgMeff=t[5]
outstruct.sat1  =t[6]
outstruct.cen1  =t[7]
outstruct.Density=t[8]
outstruct.sat2=t[9]
outstruct.cen2=t[10]


return,outstruct
end
